/*
 * @Author: tangchuan 1944302118@qq.com
 * @Date: 2024-03-26 11:31:23
 * @LastEditors: tangchuan 1944302118@qq.com
 * @LastEditTime: 2024-03-26 14:48:44
 * @FilePath: \jeecg-novel\src\views\author\workApplication\WorkSign.api.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';

const { createConfirm } = useMessage();

enum Api {
  list = '/work_sign/workSign/list',
  save = '/work_sign/workSign/add',
  edit = '/work_sign/workSign/edit',
  deleteOne = '/work_sign/workSign/delete',
  deleteBatch = '/work_sign/workSign/deleteBatch',
  importExcel = '/work_sign/workSign/importExcel',
  exportXls = '/work_sign/workSign/exportXls',
  countryList = '/novel/book/getAllCountriesNames',
  statusUpdate = '/work_sign/workSign/updateStatus'
}

/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 批量删除
 * @param params
 * @param handleSuccess
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const saveOrUpdate = (params) => {
  return defHttp.post({ url: Api.statusUpdate, params }, { isTransformResponse: false });
};

/**
 * 获取国家下拉
 */
export const getCountry = () => {
  return defHttp.post({ url: Api.countryList, params: {} }, { isTransformResponse: false });
};
